ButtonUtility.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. using System.Reflection;
  3. using System.Collections.Generic;
  4. namespace ExternPropertyAttributes.Editor
  5. {
  6. public static class ButtonUtility
  7. {
  8. public static bool IsEnabled(Object target, MethodInfo method)
  9. {
  10. EnableIfAttributeBase enableIfAttribute = method.GetCustomAttribute<EnableIfAttributeBase>();
  11. if (enableIfAttribute == null)
  12. {
  13. return true;
  14. }
  15. List<bool> conditionValues = PropertyUtility.GetConditionValues(target, enableIfAttribute.Conditions);
  16. if (conditionValues.Count > 0)
  17. {
  18. bool enabled = PropertyUtility.GetConditionsFlag(conditionValues, enableIfAttribute.ConditionOperator, enableIfAttribute.Inverted);
  19. return enabled;
  20. }
  21. else
  22. {
  23. string message = enableIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work";
  24. Debug.LogWarning(message, target);
  25. return false;
  26. }
  27. }
  28. public static bool IsVisible(Object target, MethodInfo method)
  29. {
  30. ShowIfAttributeBase showIfAttribute = method.GetCustomAttribute<ShowIfAttributeBase>();
  31. if (showIfAttribute == null)
  32. {
  33. return true;
  34. }
  35. List<bool> conditionValues = PropertyUtility.GetConditionValues(target, showIfAttribute.Conditions);
  36. if (conditionValues.Count > 0)
  37. {
  38. bool enabled = PropertyUtility.GetConditionsFlag(conditionValues, showIfAttribute.ConditionOperator, showIfAttribute.Inverted);
  39. return enabled;
  40. }
  41. else
  42. {
  43. string message = showIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work";
  44. Debug.LogWarning(message, target);
  45. return false;
  46. }
  47. }
  48. }
  49. }